package com.cs543.j.client.cloudService.storage;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


import android.util.Base64;
import android.util.Log;


public class JSON2File implements OnRPCFinishListener {
	
	File location;
	
	

	public JSON2File(File location) {
		super();
		this.location = location;
	}

	public void onFinish(Object result) {
		
		
			String fileBase64 =  (String)  result;
			
			byte[] fileArray = Base64.decode(fileBase64, Base64.URL_SAFE);
			
			Log.d("JSON2File", "Location : " + location.getPath());
			
			try {
				location.getParentFile().mkdirs();
				
				FileOutputStream stream = new FileOutputStream(location);
				
				stream.write(fileArray);
				stream.flush();
				stream.close();
				
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		
		
	}

}
